const express = require('express');
const router = express.Router();
const $common = require('../utils/common');

// 数据库
const $db = require('../db');

// 学生列表
router.get('/list', (req, res) => {
    let params = req.query || req.params;
    let classId = params.classId;

    let sql = classId?$db.sql.student.list_classId:$db.sql.student.list;
	$db.query(sql, [classId]).then(data=>{
		res.send({
			code:200,
			msg:"操作成功",
			data:data
		});
		res.end();
	})
})

// 新增学生
router.post('/add', (req, res) => {
	let sql = $db.sql.student.add;
	let studentId = 'SS' + $common.genID();
    let studentName = req.body.studentName;
    let sex = req.body.sex;
    let classId = req.body.classId;
	$db.query(sql, [studentId,studentName,sex,classId]).then(data=>{
		res.send({
			code:200,
			msg:"操作成功"
		});
		res.end();
	})
})

module.exports = router